﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Security.Cryptography;
using System.Text;

namespace handvn.Models
{
    public class UserDAO
    {
        public List<User> laydanhsachKH()
        {
            var db = new HandvnContext();
            var query = from p in db.Users
                        select p;
            List<User> danhsach = query.ToList();
            return danhsach;
        }
        public bool ktTrung(User model)
        {
            List<User> danhsach = laydanhsachKH();
            foreach (User us in danhsach)
            {
                if (us.Username == model.Username)
                    return false;
            }
            return true;
        }
        public string GetMD5(string str)
        {

            MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();

            byte[] bHash = md5.ComputeHash(Encoding.UTF8.GetBytes(str));

            StringBuilder sbHash = new StringBuilder();

            foreach (byte b in bHash)
            {

                sbHash.Append(String.Format("{0:x2}", b));

            }

            return sbHash.ToString();

        }
    }
}